/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package varx.lms.model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import varx.lms.SessionManager;

/**
 *
 * @author FF
 */
public class WarehouseModel extends Model {
    Connection conn;
    
    
    //SELECT * FROM  `warehouse` LIMIT 0 , 30

    public WarehouseModel() {
        super("warehouse");
        this.conn = SessionManager.getConnection();
    }
    
    
    public ResultSet getWareHouses(int start){
        ResultSet resultSet=null;
        String SQL;
        try {
            SQL="SELECT * FROM `warehouse` LEFT JOIN `user` ON `warehouse`.`manager_id` = `user`.`id` limit "+start+", 20";
            return conn.createStatement().executeQuery(SQL);
        } catch (SQLException ex) {
            System.out.println(ex);
        }
        return resultSet;
    }
    
    
    public static int getFreeWarehouser(String volume){
        String sql="SELECT `id` FROM `warehouse` WHERE `remain`>"+volume;
        try {
            ResultSet result=SessionManager.getConnection().createStatement().executeQuery(sql);
            if(result.next()){
                return result.getInt(1);
            }else{
                return 0;
            }
        } catch (SQLException ex) {
            System.out.println(ex);
        }
        return 0;
    }
}